-
Notifications
You must be signed in to change notification settings - Fork 80
adding dither function #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: default
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your contribution.
Sorry it took so long for someone to review your PR. This is just a read-only mirror of the upstream Mercurial repository. (But we try to port PR from here to the upstream repository if possible.)
I haven't checked the new function yet. But I left a few comments about the coding style that is used in Octave.
For the time being, I only took a look at the function documentation and had a very quick look at the function bodies (mostly for style).
I didn't bother to leave a comment at each and every line where the style should be adapted. But I tried to describe the coding style at some examples.
scripts/image/dither.m
Outdated
print_usage; | ||
endif | ||
if ndims (RGB) == 2 | ||
RGB = cat (3, RGB, RGB, RGB); % Duplicate grayscale to RGB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For end-of line comments, use two spaces and a single #
as the comment character.
scripts/image/dither.m
Outdated
endif | ||
endif | ||
if ndims (RGB) != 3 || size (RGB, 3) != 3 | ||
error('dither: RGB must be an m x n x 3 array.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a whitespace between function name and opening parenthesis.
scripts/image/dither.m
Outdated
if ndims (RGB) != 3 || size (RGB, 3) != 3 | ||
error('dither: RGB must be an m x n x 3 array.'); | ||
end | ||
if !ismatrix (map) || size (map, 2) != 3 || min (map(:)) < 0 || max (map(:)) > 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a space after the negation operator (i.e., ! ismatrix (map)
).
Use parenthesis around the condition in if
statements.
scripts/image/dither.m
Outdated
endif | ||
Qe = min (Qe, 16); % Cap Qe to avoid excessive precision | ||
|
||
% Scale RGB and map to [0, 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ##
to introduce comments that span the entire line.
## @deftypefn {Function File} {@var{X} = } dither (@var{RGB}, @var{map}) | ||
## @deftypefnx {Function File} {@var{X} = } dither (@var{RGB}, @var{map}, @var{Qm}, @var{Qe}) | ||
## @deftypefnx {Function File} {@var{BW} = } dither (@var{I}) | ||
## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a one-line description of the function if possible.
scripts/image/dither.m
Outdated
## @code{@var{X} = dither (@var{RGB},@var{map})} creates an indexed image | ||
## approximation, using the color provided in the colormap, and uses dithering | ||
## to increase apparent color resolution. Floyd-Steinberg error filter is used: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is pretty long. Consider splitting it into two sentences.
scripts/image/dither.m
Outdated
## to increase apparent color resolution. Floyd-Steinberg error filter is used: | ||
## [ x 7] | ||
## [3 5 1] / 16 | ||
## It used a raster scan and no weight renormalization at boundaries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo? "used" -> "uses"
scripts/image/dither.m
Outdated
## It used a raster scan and no weight renormalization at boundaries. | ||
## The default values are used: @var{Qm}=5, and @var{Qe}=8. | ||
## | ||
## Inputs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually don't use "section headings" like this. Also note, that texinfo will convert this and the following four lines into one single long line.
scripts/image/dither.m
Outdated
## error calculations in the Floyd-Steinberg error diffusion algorithm. | ||
## It controls the precision of the error values that are calculated and | ||
## propagated during dithering. If @var{Qe} < @var{Qm}, the error diffusion | ||
## process may lose precision, therefore dithering cannot be performed, and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full-stop after "precision".
I've made an implementation of the dither function, compatible with Matlab implementation (https://www.mathworks.com/help/matlab/ref/dither.html). In Matlab it seems not to be a part of Image package, so I guess it would also fit directly into octave core.